<template>
	<view>
		<my-search @click="waibusosuo"></my-search>
		<view class="fenlei-view">
			<!-- 左边导航 -->
			<scroll-view class="daohang" scroll-y="true" :style="{height:wh +'px'}">
				<block v-for="(item,i) in cateList" :key="i">
					<view :class="['zuodao' , i === active ? 'active':'']" @click="activedianji(i)">{{item.cat_name}}
					</view>
				</block>
			</scroll-view>
			<!-- 右边分类栏 -->
			<scroll-view class="fenlei" style="background-color: white;" scroll-y="true" :style="{height:wh +'px'}"
				:scroll-top="topjuli">
				<view class="biaoti-view" v-for="(item2,i2) in cateLevel2" :key="i2">
					<view class="biaoti">
						/ {{item2.cat_name}} /
					</view>
					<view class="fenlei-ge">
						<view class="fenlei-tu" v-for="(item3,i3) in item2.children" :key="i3"
							@click="gotoGoodsList(item3)">
							<!-- 图片 -->
							<image :src="item3.cat_icon"></image>
							<!-- 名称 -->
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				//可以使用的手机页面的
				wh: 0,
				// 导航分类存放
				cateList: [],
				active: 0,
				// 右分类存放
				cateLevel2: [],
				//切换页面时和top的距离
				topjuli: 0

			};
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync()
			//windowHeight是页面可以用的尺寸
			this.wh = sysInfo.windowHeight-50
			this.getCateList()
		},
		methods: {
			async getCateList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/categories')
				if (res.meta.status != 200) return uni.$showMsg()
				this.cateList = res.message
				console.log(res.message)
				this.cateLevel2 = res.message[0].children
			},
			activedianji(i) {
				this.active = i

				this.cateLevel2 = this.cateList[i].children
				// 右侧分类栏和top的距离
				this.topjuli = this.topjuli === 0 ? 1 : 0
			},
			// 跳转到分类商品页面
			gotoGoodsList(item) {
				uni.navigateTo({
					url: '/subpkg/goods_list/goods_list?cid=' + item.cat_pid
				})
			},
			waibusosuo(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		


	},
	}
</script>

<style lang="scss">
	.fenlei-view {
		display: flex;

		.daohang {
			width: 120px;

			.zuodao {
				background-color: #F7F7F7;
				line-height: 60PX;
				text-align: center;
				font-size: 12px;
				position: relative;

				// &？
				&.active {
					background-color: #FFFFFF;

					&::before {
						// ？
						content: '';
						display: block;
						width: 3px;
						height: 30px;
						background-color: red;
						position: absolute;
						top: 50%;
						left: 0;
						// 撤自己我百分之50%
						transform: translateY(-50%);
					}
				}
			}
		}
	}

	.biaoti {
		text-align: center;
		font-size: 12px;
		// 加粗
		font-weight: bold;
		padding: 15px 0;
	}

	.fenlei-ge {
		display: flex;
		flex-wrap: wrap;

		.fenlei-tu {
			width: 33.33%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			//文本居中
			align-items: center;
			margin-bottom: 10px;

			image {
				width: 60px;
				height: 60px;
			}

			text {
				font-size: 12px;
			}
		}
	}
</style>
